﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sora.Data.DataFormatProviders;
using System.IO;
using Sora.Data;

namespace Sora.HelpSystem.Package.DataFormatters
{
    public class UriDataFormatProvider : IDataFormatProvider
    {
        #region IDataFormatProvider Members

        public object FromStream(IDatabase caller, Stream source)
        {
            var string_formatter = DataFormatsManager.SystemManager.GetFormatProvider(typeof(string));
            return new Uri((string)string_formatter.FromStream(caller, source));
        }

        public Type GetValueType()
        {
            return typeof(Uri);
        }

        public void ToStream(IDatabase caller, Stream target, object value)
        {
            var string_formatter = DataFormatsManager.SystemManager.GetFormatProvider(typeof(string));
            var uri = value as Uri;

            string_formatter.ToStream(caller, target, uri != null ? uri.AbsoluteUri : String.Empty);
        }

        #endregion
    }
}
